<%@ Page Language="C#" MasterPageFile="~/Views/Layout.Master" AutoEventWireup="true" 
    Inherits="System.Web.Mvc.ViewPage" 
    Title="Search Work Orders" %>
<%@ Import Namespace="Microsoft.Web.Mvc"%>
<%@ Import Namespace="Headspring.Training.UI.Models"%>
<%@ Import namespace="Headspring.Training.Core.Model"%>
<%@ Import namespace="MvcContrib"%>
<%@ Import namespace="System.Web.Mvc"%>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server">
<p style="text-align:left">
    <form action="<%=Url.Action("list") %>" method="get">
	    <table>
		    <tr>
			    <th>Creator</th>
			    <th>Assignee</th>
			    <th>Status</th>
			    <td></td>
		    </tr>
		    <tr>
			    <td><%=Html.DropDownList("creator", ViewData.Get<EmployeeOptionalSelectList>("creators")) %></td>
			    <td><%=Html.DropDownList("assignee", ViewData.Get<EmployeeOptionalSelectList>("assignees")) %></td>
			    <td><%=Html.DropDownList("status", ViewData.Get<WorkOrderStatusOptionalSelectList>()) %></td>
			    <td><%=Html.SubmitButton("search", "Search", new {width = "100"}) %></td>
		    </tr>
	    </table>
	</form>
</p>
<asp:DataGrid ID="grdWorkOrders" runat="server" AutoGenerateColumns="false" CellPadding="3" Width="100%" BorderWidth="0">
	<AlternatingItemStyle BackColor="#FFFFFF" />
    <Columns>
        <asp:HyperLinkColumn DataNavigateUrlFormatString="~/workorder/edit?workordernumber={0}"
            DataNavigateUrlField="Number" DataTextField="Number" HeaderText="WO #" HeaderStyle-Font-Bold="true" ItemStyle-VerticalAlign="Top" HeaderStyle-Wrap="false" />
        <asp:TemplateColumn HeaderText="Creator" ItemStyle-VerticalAlign="Top" HeaderStyle-Font-Bold="true">
            <ItemTemplate>
                <%#Eval("Creator")%>
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn HeaderText="Assignee" ItemStyle-VerticalAlign="Top" HeaderStyle-Font-Bold="true">
            <ItemTemplate>
                <%#Eval("Assignee")%>
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn HeaderText="Status" ItemStyle-VerticalAlign="Top" ItemStyle-Wrap="false" HeaderStyle-Font-Bold="true">
            <ItemTemplate>
                <%#((WorkOrder)Container.DataItem).Status.ToString() %>
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:BoundColumn HeaderText="Title" DataField="Title" ItemStyle-VerticalAlign="Top" HeaderStyle-Font-Bold="true" />
        <asp:TemplateColumn HeaderText="LastChangeDate" ItemStyle-VerticalAlign="Top" ItemStyle-Wrap="false" HeaderStyle-Font-Bold="true">
            <ItemTemplate>
                <%# ((WorkOrder)Container.DataItem).LastChangeDate.HasValue ? ((WorkOrder)Container.DataItem).LastChangeDate.Value.ToShortDateString() : String.Empty %>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
</asp:DataGrid>

</asp:Content>
<script runat="server">

    protected override void OnLoadComplete(EventArgs e)
    {
        if (ViewData.Contains<WorkOrder[]>())
        {
            grdWorkOrders.DataSource = ViewData.Get<WorkOrder[]>();
            grdWorkOrders.DataBind();
        }
    }

</script>
